//
//  UIButton+initButton.m
//  aaa
//
//  Created by dllo on 16/3/4.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "UIButton+initButton.h"
#import "UIImageView+WebCache.h"

@implementation UIButton (initButton)

+ (instancetype)buttonWithTitle:(NSString *)title
                          frame:(CGRect)frame
                         target:(id)target
                         action:(SEL)action
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    
    button.frame = frame;
    
    if ([title hasSuffix:@".png"] || [title hasSuffix:@".jpg"]) {
        [button setBackgroundImage:[[UIImage imageNamed:title] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    } else {
        [button setTitle:title forState:UIControlStateNormal];
        
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}

@end
